﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using QuickTweet.Common;
using System.Windows.Input;
using System.Windows.Data;
using QuickTweet.Common.Commanding;

namespace QuickTweet.ViewModels
{
    public class TweetPopupViewModel : ViewModelBase
    {
        #region Properties

        private int MAX_TWEET_LENGTH = 140;

        public ICommand SendTweetCommand { get; private set; } // In Binding con la View 

        private string tweet;
        public string Tweet
        {
            get
            {
                return tweet;
            }
            set
            {
                if (UpdateProperty(value, ref tweet))
                {                   
                    OnPropertyChanged("Tweet");
                    OnPropertyChanged("RemainingCharacters");
                    OnPropertyChanged("CanSendTweet");
                }
            }
        }

        public int RemainingCharacters
        {
            get
            {
                return MAX_TWEET_LENGTH - tweet.Length;
            }
        }

        public bool CanSendTweet
        {
            get 
            {
                return (!string.IsNullOrWhiteSpace(tweet));
            }
        }

        #endregion

        public TweetPopupViewModel()
        {
            tweet = string.Empty;

            Binding binding = new Binding("CanSendTweet");
            binding.Source = this;
            SendTweetCommand = new DelegateCommand(args => SendTweet(args), binding);   
        }

        private void SendTweet(object parameter)
        {
            
        }
    }
}
